package pers.gxm.bridge;

import java.io.*;

public class FileDisplayImpl extends DisplayImpl {
    public static void main(String[] args) {
        Display fd = new Display(new FileDisplayImpl("LinkPage.html"));
        fd.display();
        System.out.println("再来一次");
        fd.display();


    }

    private String filename;
    private BufferedReader br;

    public FileDisplayImpl(String filename){
        this.filename = filename;
    }
    @Override
    public void rawOpen() {
        File file = new File(filename);
        try {
            br = new BufferedReader(new FileReader(file));
//            br.mark();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public void rawPrint() {
        String line;
        try {
            while((line = br.readLine()) != null){
                System.out.println(line);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void rawClose() {
        try {
            br.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
